package main

import (
	_ "LiquidMeasurement/routers"
	"github.com/astaxie/beego"
//	"LiquidMeasurement/lib"
	m"LiquidMeasurement/models"
	"github.com/astaxie/beego/orm"
	_"github.com/go-sql-driver/mysql"
//	"fmt"
//	"github.com/astaxie/beego/example/chat/controllers"
	"os"
	//"fmt"
)

func init() {
	orm.RegisterDriver("mysql", orm.DRMySQL)

	orm.RegisterDataBase("default", "mysql", "root:123456@/liquid_measurement?charset=utf8")
}
func addAdmin(){
	if  len(os.Args) == 2 && os.Args[1] == "adduser" {


		department := m.Department{Name:"主管", Detail:"qqq"}
		m.AddDepartment(&department)
		permision, _ := beego.AppConfig.Int("admin_permission")
		//department,_:=beego.AppConfig.Int("admin_department")
		admin := m.Admin{Tel:beego.AppConfig.String("admin_tel"),
			UserName:beego.AppConfig.String("admin_name"),
			Passwd:beego.AppConfig.String("admin_pw"),
			JobID:beego.AppConfig.String("admin_job_id"),
			IdentifyCard:beego.AppConfig.String("admin_identify_card"),
			Department:&department,
			Permission:int8(permision)}
		m.AddAdmin(&admin)
		os.Exit(0)
	}
}
//func addTestUser(){
//	user := m.User{Tel:"15928972923",UserName:"xujianhua"}
//	m.AddUser(&user)
//}

func main() {
//	o := orm.NewOrm()
//	o.Using("default")
//
//	admin := m.Admin{
//		JobID : "123",
//		Tel :"18070581069",
//		Passwd :"123456",
//		IdentifyCard : "360782199207210036",
//		Department : 1}
//
//	fmt.Println(o.Insert(admin))
//	lib.InitLog()
//	beego.Admin = "localhost"
//	beego.AdminHttpPort = 8088
//	beego.EnableAdmin = true
	//beego.SetLogger("file", `{"filename":"LiquidMeasurement.log"}`)
	//beego.SetLogFuncCall(true)
	
	beego.Info("system start\n")

	orm.RunCommand()
	addAdmin()
	beego.Run()

}

